#pragma once
#include "cryptengine.h"
#include <stdint.h>


struct _Key
{
	uint32_t k0, k1, k2, k3;
};

union Encryptionkey
{
	_Key kvar;
	uint32_t k[4];
};

struct _Data
{
	uint32_t v0, v1;
};

union EncryptionData
{
	_Data vvar;
	uint32_t v[2];
};

class TinyEngine :
	public CryptEngine
{
public:
	TinyEngine(uint32_t k0, uint32_t k1, uint32_t k2, uint32_t k3, size_t);
	virtual bool process(DataSource*, DataTarget*, std::string, EncryptionMode);
protected:
	static const uint32_t delta = 0x9e3779b9;
	static const size_t block_size = 8;	// eight bytes 
	size_t getBlock(DataSource* source); // read block_size bytes from dataSource
	size_t writeBlock(DataTarget* target); // write block_size bytes to dataSource
	size_t numberOfRounds;

	// more elegant way to store the key
	Encryptionkey key;
	EncryptionData data;	// represent one block of data

	uint32_t sum;
	bool processPair(EncryptionMode);
	void encrypt();						// perform one iteration
	void decrypt();						// perform one iteration
};

